import { setLoading } from '@/views/enterprise/service/state' // 假设状态管理文件名为 state.js
import { rsDeleteService } from '@/api/enterprise'
import { info_ListGetService } from '@/api/enterprise'
import { ref } from 'vue'
/*浏览器本地导出文件方法 */
export const downloadTextAsFile = (fileName, textContent) => {
  const blob = new Blob([textContent], { type: 'text/plain;charset=utf-8' })
  const url = URL.createObjectURL(blob)
  const downloadLink = document.createElement('a')
  downloadLink.href = url
  downloadLink.download = fileName
  downloadLink.style.display = 'none'
  document.body.appendChild(downloadLink)
  downloadLink.click()
  window.URL.revokeObjectURL(url)
  document.body.removeChild(downloadLink)
}
/*删除简历*/
export const rsDelete = async (informationId) => {
  if (
    await ElMessageBox.confirm('你确认删除该简历相关信息吗？', '温馨提示', {
      type: 'warning',
      confirmButtonText: '确认',
      cancelButtonText: '取消'
    })
  ) {
    setLoading(true) // 使用函数来设置加载状态
    try {
      await rsDeleteService(informationId)
      ElMessage({ type: 'success', message: '删除成功' })
    } catch (error) {
      console.error('删除信息时发生错误:', error)
      ElMessage({ type: 'error', message: '删除失败' })
    } finally {
      setLoading(false) // 在 finally 块中恢复加载状态
    }
  }
}

/*获取列表 */
const Info_list = ref([])
export const get_list = async () => {
  setLoading(true)
  try {
    const res = await info_ListGetService()
    Info_list.value = res.data.data
    ElMessage({ type: 'success', message: '刷新成功' })
  } catch (error) {
    console.error('刷新发生错误:', error)
    ElMessage({ type: 'error', message: '刷新失败' })
  } finally {
    setLoading(false) // 在 finally 块中恢复加载状态
  }
  return Info_list.value
}
